import router from './index'
import store from '../store'
const whiteList = ['/']
router.beforeEach((to, from, next) => {
   if (store.getters.token) {
      console.log(store.getters.currentUser.role);
      // 购票员可以进入除管理外的所有页面
      // 管理员只能进入登录页和管理页
      if (store.getters.currentUser.role == 1) {
         if (to.path == '/') {
            next('/index')
         } else {
            if (to.path.startsWith('/manage')) next('/index')
            else next()
         }
      }
      else if (store.getters.currentUser.role == 2) {
         if (to.path.startsWith('/manage/movie-manager')){
            next()
         }
         else { 
            next('/manage/movie-manager/movie')
         }
      }
      else if (store.getters.currentUser.role == 3) {
         if (to.path.startsWith('/manage/sys-manager')) {
             next()
         } else { 
            next('/manage/sys-manager/cinema') 
         }
      }
   } else {
      if (whiteList.includes(to.path)) next()
      else next('/')
   }
})